﻿@page "/settings/log"
@using North.Core.Common;

@inject IJSRuntime JS
@inject ILogger _logger
@inject ISnackbar _snackbar
@inject IHttpContextAccessor _accessor
@inject NavigationManager _navigationManager
@inject AppSetting _appSetting

<AuthorizeView Roles="User">
    <MudStack Spacing="10" Row AlignItems="AlignItems.Center" Class="message_warn">
        <MudImage Src="icons/warn.svg" Width="180" Elevation="0" Class="rounded-lg ma-4" />
        <MudLink Href="/" Color="Color.Warning" Style="font-weight:bold; font-size:34px;">您的权限不足，无法访问</MudLink>
    </MudStack>
</AuthorizeView>
<AuthorizeView Roles="System">
    <MudStack Spacing="6" Style="padding-left:37px; margin-top:20px;" id="page">
        <!-- 日志输出路径 -->
        <MudStack Spacing="2">
            <p class="menu_text">输出路径</p>
            <MudStack Spacing="0" Row AlignItems="AlignItems.Center" Style="width:fit-content; height:35px;">
                <MudTextField @bind-Value="@LogSetting.Output"
                            Margin="Margin.Dense" Variant="Variant.Outlined"
                            Style="width:90%; max-width:260px; height:35px;" />
                <MudTooltip Text="点击下载日志" Placement="Placement.Right">
                    <MudIconButton Icon="@Icons.Material.Filled.Download" Variant="Variant.Outlined" Color="Color.Info" OnClick="DownloadLogfile" />
                </MudTooltip>
            </MudStack>
        </MudStack>
        <!-- 日志输 出级别 -->
        <MudStack Spacing="2">
            <MudTooltip Text="只有等级范围内的日志会被输出" Placement="Placement.Right">
                <p class="menu_text">输出级别</p>
            </MudTooltip>
            <MudStack Row Style="width:fit-content;" AlignItems="AlignItems.Center">
                <MudSelect @bind-Value="@LogSetting.Levels.Min"
                            Variant="Variant.Outlined" Margin="Margin.Dense" AnchorOrigin="Origin.BottomCenter"
                            Style="width:90%; max-width:140px; max-height:35px;">
                        <MudSelectItem Value="LogLevel.Trace" Style="height:35px;" />
                            <MudSelectItem Value="LogLevel.Debug" Style="height:35px;" />
                        <MudSelectItem Value="LogLevel.Information" Style="height:35px;" />
                    <MudSelectItem Value="LogLevel.Warning" Style="height:35px;" />
                    <MudSelectItem Value="LogLevel.Error" Style="height:35px;" />
                        <MudSelectItem Value="LogLevel.Critical" Style="height:35px;" />
                    </MudSelect>
                <MudIcon Icon="@Icons.Material.Outlined.ArrowRightAlt" />
                <MudSelect @bind-Value="@LogSetting.Levels.Max"
                            Variant="Variant.Outlined" Margin="Margin.Dense" AnchorOrigin="Origin.BottomCenter"
                            Style="width:90%; max-width:140px; max-height:35px;">
                    <MudSelectItem Value="LogLevel.Trace" Style="height:35px;" />
                    <MudSelectItem Value="LogLevel.Debug" Style="height:35px;" />
                    <MudSelectItem Value="LogLevel.Information" Style="height:35px;" />
                    <MudSelectItem Value="LogLevel.Warning" Style="height:35px;" />
                    <MudSelectItem Value="LogLevel.Error" Style="height:35px;" />
                    <MudSelectItem Value="LogLevel.Critical" Style="height:35px;" />
                </MudSelect>
            </MudStack>
        </MudStack>
        <!-- 日志输出格式 -->
        <MudStack Spacing="2">
            <MudTooltip Text="构造方法请参照 Nlog" Placement="Placement.Right">
                <p class="menu_text">输出格式</p>
            </MudTooltip>
            <MudTextField @bind-Value="@LogSetting.Layout" Lines="4"
                            Margin="Margin.Dense" Variant="Variant.Outlined"
                            Style="width:90%; max-width:460px; line-height:1.5em;" />
        </MudStack>
        <!-- 保存/取消设置 -->
        <MudStack Row Style="width:100%;">
            <MudButton Variant="Variant.Filled" Color="Color.Tertiary" 
                        OnClick="SaveSettings" Disabled="@SaveRunning"
                        Style="width:100px;">
                @if (SaveRunning)
                {
                    <MudProgressCircular Style="width:17px; height:17px; margin-right:10px;" Indeterminate/>
                }
                <MudText>保 存</MudText>
            </MudButton>
            <MudButton Variant="Variant.Filled" Color="Color.Error" 
                        OnClick="RestoreSettings" Disabled="RestoreRunning"
                        Style="width:100px;">
                @if (RestoreRunning)
                {
                    <MudProgressCircular Style="width:17px; height:17px; margin-right:10px;" Indeterminate/>
                }
                <MudText>还 原</MudText>
            </MudButton>
        </MudStack>
    </MudStack>
</AuthorizeView>

<style>
    .menu_text {
        font-weight:bold;
    }

    #page {
        overflow: scroll;
        overflow-x: hidden;
        height: 100%;
    }

    #page::-webkit-scrollbar {
        display:none;
    }

    .message_warn {
        width:fit-content;
        height:fit-content;
        left: 0;
        top: 0;
        bottom: 100px;
        right: 0;
        position: absolute;
        margin: auto;
    }
</style>